﻿/************************************************************************
 * SMLib - State Model Library
 * Copyright (C) 2012-2013 Ali Khalili (khalili_DOT_ir_@SIGN_gmail_DOT_com)
 * **********************************************************************
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License (LGPL) published 
 * by the Free Software Foundation; either version 2.1 of the License, or (at your
 * option) any later version. This program is distributed without any
 * warranty. See the GNU Lesser General Public License for more details. 
 * ***********************************************************************
 * File         :     SMLib\Automata\Base\Symbol.cs
 * Description  :     Implement the interface ISymbol to provide having symbols of a kind T
 * Change log   :     -22 Feb 2013: Add Symbol T
 * To Do        :
 ************************************************************************/
using System;

namespace SMLib.Automata.Base
{
    /// <summary>
    /// Symbols of a kind T (implements ISymbol)
    /// </summary>
    /// <typeparam name="T">Type of Symbol</typeparam>
    public class Symbol<T> : ISymbol
    {
        /// <summary>
        /// Content of this symbol
        /// </summary>
        protected T mySymbol;

        #region ISymbol Members

        /// <summary>
        /// Access to the content value of the symbol
        /// </summary>
        public object ContentObject
        {
            get
            {
                return mySymbol;
            }
            set
            {
                mySymbol = (T)value;
            }
        }

        /// <summary>
        /// Type of the symbol
        /// </summary>
        /// <returns>Type of T (the argument of template)</returns>
        public Type TypeOfSymbol()
        {
            return typeof(T);
        }

        #endregion

        /// <summary>
        /// Equality of two Symbol of T
        /// </summary>
        /// <param name="obj">the other object to be compared with</param>
        /// <returns>true if it is equal to obj, false in other case</returns>
        public override bool Equals(object obj)
        {
            if (obj is ISymbol)
            {
                return (mySymbol.Equals(((ISymbol)obj).ContentObject));
            }
            return false;
        }

        /// <summary>
        /// Convert the symbol into the string, e.g. used for presentation of the symbol in user interface
        /// </summary>
        /// <returns>the corresponding string value of the symbol</returns>
        public override string ToString()
        {
            return mySymbol.ToString();
        }

        /// <summary>
        /// Compute hash generatedCode of the symbol
        /// </summary>
        /// <returns>the corresponding hash generatedCode</returns>
        public override int GetHashCode()
        {
            return mySymbol.GetHashCode();
        }
    }
}
